package handler

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

const (
	Success = iota
	Error
)

type Response struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data"`
}

func RestOk(c *gin.Context) {
	res := Response{
		Code:    Success,
		Message: "操作成功",
		Data:    nil,
	}
	c.JSON(http.StatusOK, res)
}

func RestData(c *gin.Context, data any) {
	res := Response{
		Code:    Success,
		Message: "操作成功",
		Data:    data,
	}
	c.JSON(http.StatusOK, res)
}

func RestFail(c *gin.Context) {
	res := Response{
		Code:    Error,
		Message: "操作失败",
		Data:    nil,
	}
	c.JSON(http.StatusOK, res)
}

func RestFailMsg(c *gin.Context, msg string) {
	res := Response{
		Code:    Error,
		Message: msg,
		Data:    nil,
	}
	c.JSON(http.StatusOK, res)
}
